package com.fosss.binarySearch;

/**
 * 递归实现二分查找算法
 */
public class BinarySearch1 {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,5,5,6,7,8,9,55};
        int index = binarySearch(arr, 0, arr.length-1, 2);
        System.out.println(index);
    }

    private static int binarySearch(int[] arr,int left,int right,int value){
        int mid=(left+right)/2;
        if(left>right){
            return -1;
        }

        if(value<arr[mid]){
            return binarySearch(arr,left,mid-1,value);
        }
        else if(value>arr[mid]){
            return binarySearch(arr,mid+1,right,value);
        }else {
            return mid;
        }

    }
}





